package http.secure.common.event;

import http.secure.common.event.entity.KeyEvent;
import org.springframework.context.ApplicationListener;


/**
 * By implementing the {@link KeyExchangeListener} interface,
 * Spring will push the <b>SM4 key</b> when the key exchange is complete.
 *
 * @see ApplicationListener
 */
public interface KeyExchangeListener extends ApplicationListener<KeyEvent> {
    @Override
    default void onApplicationEvent(KeyEvent event) {
        onKeyExchange(event.getGsid(), event.getKey(), event.getBrowserIv());
    }

    /**
     * Push SM4 key when key exchange is successful
     *
     * @param gsid      Session ID
     * @param key       SM4 KEY
     * @param browserIv Browser fingerprint
     */
    void onKeyExchange(String gsid, String key, String browserIv);
}
